package com.cuit.zuke.consumer.service.impl;

import com.cuit.zuke.consumer.mapper.CommentMapper;
import com.cuit.zuke.consumer.pojo.Comment;
import com.cuit.zuke.consumer.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class CommentServiceImpl implements CommentService {
    @Autowired
    private CommentMapper commentMapper;

    public List<Comment> queryAll(int currentPage, int pageSize) {
        return commentMapper.queryAll(currentPage, pageSize);
    }

    public int queryTotal() {
        return commentMapper.queryTotal();
    }

    public List<Comment> queryCommentByUserId(String userId, int currentPage, int pageSize) {
        return commentMapper.queryCommentByUserId(userId, currentPage, pageSize);
    }

    public int queryOneTotal(String userId) {
        return commentMapper.queryOneTotal(userId);
    }

    public void updateIsDeleted(String commentId, int isDeleted) {
        commentMapper.updateIsDeleted(commentId, isDeleted);
    }

    public Comment queryCommentByCId(String commentId) {
        return commentMapper.queryCommentByCId(commentId);
    }

    public List<Comment> queryUserByHotelId(String hotelId) {
        return commentMapper.queryUserByHotelId(hotelId);
    }

    public String maxCommentId() {
        return commentMapper.maxCommentId();
    }

    public void insertComment(Comment comment) {
        commentMapper.insertComment(comment);
    }

    public void insertHotelComment(String hotelId, String content, String userId) {
        Comment comment = new Comment();
        Date date = new Date();
        SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String maxCommentId = commentMapper.maxCommentId();
        String commentId = String.valueOf(Integer.parseInt(maxCommentId) + 1);

        comment.setHotelId(hotelId);
        comment.setContent(content);
        comment.setUserId(userId);
        comment.setCreateTime(sdf.format(date));
        comment.setCommentId(commentId);
        comment.setType(0);
        comment.setIsDeleted(1);
        this.insertComment(comment);
    }

    public void insertGoodComment(String hotelId, String content, String userId) {
        Comment comment = new Comment();
        Date date = new Date();
        SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String maxCommentId = commentMapper.maxCommentId();
        String commentId = String.valueOf(Integer.parseInt(maxCommentId) + 1);

        comment.setHotelId(hotelId);
        comment.setContent(content);
        comment.setUserId(userId);
        comment.setCreateTime(sdf.format(date));
        comment.setCommentId(commentId);
        comment.setType(1);
        comment.setIsDeleted(1);
        this.insertComment(comment);
    }
}
